<?php

    $tpl = new SimpleTemplate(VIEW.'aluno/addAluno.html');
    
    $func = new functions;
    $sel = new select;    
    $estados = $sel->uf();

    $atual = 'MG';

    foreach($estados as $uf){
        $tpl->VALUE = $uf;
        $tpl->TXT = $uf;

        ($atual == $uf)? $tpl->SELECTED = 'selected' : $tpl->clear("SELECTED");

        $tpl->block("BLOCK_UF");
    }        
  
     
    $dados = new aluno;  
    
    $result = $dados->insert('aluno',$_POST);
    $id = $dados->last_insert_id();

    if($_SERVER['REQUEST_METHOD']=='POST'){    
        $matricula = date("Y").str_pad($id, 5, "5", STR_PAD_LEFT);
    
        $dados->query("UPDATE aluno SET matricula=$matricula WHERE id=$id");
    }
    
    
    if($id)
        $func->go ("home.php?pg=alunoSuccess&action=add&id=$id");
    $tpl->show();
?>
